-
-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggested implementation of themes refactoring #1340
base: main
Are you sure you want to change the base?
Suggested implementation of themes refactoring #1340
Conversation
9d33bcc
to
e65a3f0
Compare
- introduce "grist-base", "grist-theme" and "grist-custom" css layers in order to easily handle priority of css variables and base css rules - apply css default variables and css reset on the "grist-base" layer. Note that the way default html/body css is loaded has been changed to be simpler, but maybe I assumed too much here, I didn't dig too deep to get the whole context - apply custom theme css variables on the "grist-theme" layer - a potential custom.css file should wrap its code in the "grist-custom" layer, as the updated example file suggests This will allow base/theme/custom CSS to generate the same variable names while being sure custom css takes precedence theme variables, and theme variables take precedence over default variables.
Until now themes could only describe each component variable. This made creating a theme difficult: we had to override all component variables (hundreds of them) if we wanted to change one color shade used globally. Here is an idea of a cssVars.designTokens prop that is a combination of current `colors`, `vars` and `theme` props: - all design tokens are overridable by a theme - colors are now named in a more abstract way so that it makes sense for a theme changing the primary color Everything is explained in details in the cssVars.designTokens comments
Use new design tokens on right panel header tabs, without removing component-specific variables. Component-specific variables now target designTokens, that are themselves overridable by a theme, allowing to prevent repeating lots of definitions in the theme file.
e65a3f0
to
f9027ce
Compare
Approach makes sense to me. Thank you.
Making all the tokens required in |
Great :)
So to be 100% clear, you mean at least this?
But do you also mean this?
I'd argue if we think those component-specific variables are kinda legacy and we eventually want to remove them, I'd say making them required in a theme object is maybe too much trouble? Since the idea is themes would not want to change those, as Here are a few thoughts:
Yeah I guess this way of doing was more to show the structure, indeed "grist-tokens" is not necessary. I'd argue if *everything* is listed in a theme object, the concept of "grist-base" variables is also debatable: every design token variable is tied to the theme, and then there is the custom css layer that comes on top. |
Only the variables we'd like to change from theme to theme. So yes to colors, but no to z-indexes. Padding and font size are more interesting; I can see an argument that making them required would be more of a nuisance, as they won't always change across themes. A compromise might be to make the vars (e.g. fonts, padding, etc.) optional, and the colors required, with the vars being inherited from the base layer.
No, I agree that it's too much trouble to make those required.
I had a similar thing in mind. A base theme defining the default, non-color variables makes a lot of sense to me. The current system is awkward because things live in two places, as you said. If we can narrow that down to one, that'd be great! |
- there is no more default values set in cssVars for vars being tied to a theme, meaning `colors` and `vars` do not have any value anymore. They just expose the new `tokens` object - a new theme `tokens` object exposes all the CSS variables related to the current theme. They include colors, but also font family, paddings, basically everything that was described in cssVars colors and vars. - a new theme `legacyVariables` object exposes all the previous cssVars `theme` variables that are considered legacy code. The cssVars `theme` object just consumes this new object - themes now must define tokens that were before only in cssVars `colors` and ` vars`. To help with that, there is now a Base.ts theme that describes all variables that should stay the same for most themes. - in practice, defining a new theme will mean meandescribing an object a couple dozens variables, instead of the 400+ previously. - Removed the use of ts-interface-builder as it didn't work with new types (made with generics). the gristUrls code was updated accordingly. But the AppModel that used the ThemePrefsChecker now misses the check. I actually don't understand why it was actually necessary here. Removed it for now, I need some feedback. - example of "legacy variables" handling has begun: some more generic token variables were added, that a set of legacy variables target instead of previous specific values. it shows how we could try to refactor the bunch of variables so that updating themes would then be easier. The added variables are ones matching variables that were used a lot in grist dark and grist light themes.
Hey @georgegevoian, Here is an update to move things forward. SummaryThe idea is:
Feedback neededVariable namings and impact on widget's stylingI made the choice to abstract the css variable names as much as possible. The goal is that we don't have to regularly switch in our heads between the consumed in the codebase name ( So there is some code to map some js object keys to existing css var names. Unfortunately I only figured out later that theme variables in widget iframes was loaded differently. And from what I understand I can't import common files in the plugin-related code? Which means for now I can't go find the css variable name matching the theme key in the plugin code, like I do in the default Any advice on what I could do there? My intuition would be to actually remove the js object key <> css var name manual mapping and just generate css variable names based on the JS keys. So that TS checkersI had trouble with the ts-interface-checker related code, because it doesn't handle generics. I ended up just… removing the I'm not against a little bit of explanation here if what I did is not ok, I assume I missed something :) Next stepsIf what you see seems globally find for you, here what I wanted to continue on:
What do you think? Thanks a lot. |
Context
Here is an example of implementation following discussions in #1295 (up until George's comment).
Proposed solution
Everything is detailed in comments and commit messages, here is a summary of it:
cssVars.colors
andcssVars.vars
, have one big unique object that holds all the design tokens (cssVars.designTokens
), that can all be overriden by a theme. Contrary to before where default colors could not be changed. The idea would be that the new object replaces the 2 others.cssVars.theme
, make the specific component variables target the new design tokens. In the end, in each Theme, specific component variables can be removed, and we can decide to define only the more global design token values (see GristDark).Questions that popped up:
cssVars
being used for the undefined variables. I'm not sure this is a great idea as it could lead to oversights when implementing new themes or updating current ones. I'm not sure it's actually an issue either. As we can easily create a new Theme by extending an existing one anyway. What do you think?Related issues
#1295
Has this been tested?
ping @dsagal @georgegevoian